package com.example.login.controller;

import com.example.common.domain.Result;
import com.example.login.domain.dto.EmployeeLoginCaptchaDTO;
import com.example.login.domain.dto.EmployeeLoginPasswordDTO;
import com.example.login.domain.vo.EmployeeLoginVO;
import com.example.login.service.EmployeeAuthService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Tag(name="登录接口相关")
@Slf4j
@RestController
@RequestMapping("/login/employee")
@RequiredArgsConstructor
public class EmployeeLoginController {
    private final EmployeeAuthService employeeService;
    /**
     * 密码登录
     *
     * @param employeeLoginDTO
     * @return
     */
    @PostMapping("/password")
    @Operation(summary ="员工密码登录")
    public Result<EmployeeLoginVO> loginByPassword(@RequestBody @Validated EmployeeLoginPasswordDTO employeeLoginDTO) {
        log.info("员工登录：{}", employeeLoginDTO);
        EmployeeLoginVO employeeLoginVO = employeeService.loginByPassword(employeeLoginDTO);
        return Result.success(employeeLoginVO);
    }

    @PostMapping("/captcha")
    @Operation(summary ="员工验证码登录")
    public Result<EmployeeLoginVO> loginBycaptcha(@RequestBody @Validated EmployeeLoginCaptchaDTO employeeLoginCaptchaDTO) {
        log.info("员工验证码登录：{}", employeeLoginCaptchaDTO);
        EmployeeLoginVO employeeLoginVO = employeeService.loginByCaptcha(employeeLoginCaptchaDTO);
        return Result.success(employeeLoginVO);
    }
}
